#!/usr/bin/env python

from __future__ import print_function
from ctypes import CDLL
import sys

def help():
    print("""    usage: m lock [ help ]

    Examples:
      m lock     # lock session""")
    sys.exit()

def lock():
    path = '/System/Library/PrivateFrameworks/login.framework/Versions/Current/login'
    try:
        login = CDLL(path)
        login.SACLockScreenImmediate()
    except OSError:
        print("Couldn't load framework: ", path)
    except AttributeError:
        print("Function is not available.")

def main(args):
    for arg in args:
        if arg == 'help':
            help()

    lock()

if __name__ == "__main__":
    main(sys.argv[1:])


# vim: ts=4 sw=4 softtabstop=4 expandtab
